package com.mk.admin.service.impl;

import com.mk.admin.mapper.FeedBackMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.FeedBackEntity;
import com.mk.admin.model.vo.FeedBackVo;
import com.mk.admin.service.FeedBackService;
import com.mk.admin.util.DateTool;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FeedBackServiceImpl implements FeedBackService {
    @Autowired
    private FeedBackMapper feedBackMapper;

    @Override
    public ResultDto select(FeedBackVo vo) {
        FeedBackEntity entity = JSONCopy.copy(vo, FeedBackEntity.class);

        return ResultDto.data(feedBackMapper.count(entity), feedBackMapper.select(entity));
    }

    @Override
    public ResultDto add(FeedBackVo feedBackVo) {
        FeedBackEntity entity = JSONCopy.copy(feedBackVo, FeedBackEntity.class);
        entity.setCreateTime(DateTool.format());
        return ResultDto.data(feedBackMapper.insert(entity));
    }

    @Override
    public ResultDto update(FeedBackVo feedBackVo) {
        FeedBackEntity entity = JSONCopy.copy(feedBackVo, FeedBackEntity.class);
        entity.setAnswerTime(DateTool.format());
        return ResultDto.data(feedBackMapper.updateById(entity));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(feedBackMapper.deleteById(id));
    }

    @Override
    public ResultDto status(int id) {
        return ResultDto.data(feedBackMapper.status(id));
    }


}
